// utils/jwt.go
package utils

import (
	"github.com/gin-gonic/gin"
	"github.com/golang-jwt/jwt/v4"
)

func GetUserIDFromContext(c *gin.Context) uint {
	if claims, exists := c.Get("user"); exists {
		if userClaims, ok := claims.(jwt.MapClaims); ok {
			if userID, ok := userClaims["userID"].(float64); ok {
				return uint(userID)
			}
		}
	}
	return 0
}

func GetUsernameFromContext(c *gin.Context) string {
	if claims, exists := c.Get("user"); exists {
		if userClaims, ok := claims.(jwt.MapClaims); ok {
			if username, ok := userClaims["username"].(string); ok {
				return username
			}
		}
	}
	return ""
}
